package com.xma.springcloud.alibaba.controller;

import com.xma.springcloud.alibaba.entity.TAccout;
import com.xma.springcloud.alibaba.service.TAccoutService;
import com.xma.springcloud.common.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * (TAccout)表控制层
 *
 * @author makejava
 * @since 2020-07-07 18:17:13
 */
@RestController
@Slf4j
public class TAccoutController {
    /**
     * 服务对象
     */
    @Resource
    private TAccoutService tAccoutService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TAccout selectOne(@RequestParam("userId") Long id) {
        return this.tAccoutService.queryById(id);
    }

    @PostMapping(value = "/account/decrease")
    public ResponseResult decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money){
        log.info("------订单微服务开始调用账户，做扣减");
        tAccoutService.update(userId,money);
        log.info("------订单微服务开始调用账户，做扣减end");
        return new ResponseResult(200,"订单微服务调用账户成功");
    }

}